package juc.java8;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public class StreamDemo {


    public static void main(String[] args) {
//        List<Stu> stuList = Arrays.asList(
//                new Stu(1,"hh",22),
//                new Stu(2,"aa",22),
//                new Stu(3,"bb",32),
//                new Stu(4,"cc",42),
//                new Stu(5,"dd",52)
//        );
//
//
//        Stream<Stu> stream = stuList.stream().filter((a)-> {
//            System.out.println("测试迭代几次");
//            return a.getAge() > 40;
//        });
//
//        stream.forEach(System.out::println);
        List<String> stringList = Arrays.asList("aa", "bb", "cc", "dd");
        stringList.stream().map((x)->x.length()).forEach(System.out::println);
        stringList.stream()
                .map((x)->x.toUpperCase()).forEach(System.out::println);

    }

    /**
     * 字符串拆分成字符后组成一个字符类型的流
     * @param str
     * @return
     */
    public static Stream<Character> filterCharacter(String str){
        List<Character> characterList = new ArrayList<>();
        for (Character ch: str.toCharArray()
                ) {
            characterList.add(ch);
        }
        return characterList.stream();
    }

}
